

##    def rotateSpins(self, thetaZ, thetaX):
##        rotationZArray = array(((cos(-thetaZ),sin(-thetaZ),0),(-sin(-thetaZ),cos(-thetaZ),0),(0,0,1)))  # CCW rotation about Z
##        rotationXArray = array(((1,0,0),(0,cos(-thetaX),sin(-thetaX)),(0,-sin(-thetaX),cos(-thetaX))))  # CCW rotation about X
####        rotationYArray = array(((cos(-thetaY),0,-sin(-thetaY)),(0,1,0),(sin(-thetaY),0,cos(-thetaY))))
##
##        for x in range(self.nSpinsX):
##            for y in range(self.nSpinsY):
##                self.spinArray[x][y][0] = matrixmultiply(rotationZArray,self.spinArray[x][y][0])
##                self.spinArray[x][y][0] = matrixmultiply(rotationXArray,self.spinArray[x][y][0])
##
##    def resetCommonAxis(self):
##        currentAxis = self.returnCommonAxis()          # more direct measures could be used...
##
##        if currentAxis[1] != 0.0:  thetaZ = arctan(currentAxis[0]/currentAxis[1])
##        else: thetaZ = pi/2.0
##        
##        rotationZArray = array(((cos(-thetaZ),sin(-thetaZ),0),(-sin(-thetaZ),cos(-thetaZ),0),(0,0,1)))
##        currentAxisTwo = matrixmultiply(rotationZArray,currentAxis)
##
##        if currentAxisTwo[2] != 0.0: thetaX = arctan(currentAxisTwo[1]/currentAxisTwo[2])
##        else: thetaX = pi/2.0
##
##        self.rotateSpins(thetaZ,thetaX)



##        maxEnergy = 0.0
##        
##        for x in range(self.nSpinsX):
##            for y in range(self.nSpinsY):
##                yDir = abs(self.couplingYArray[y][(y+1)%self.nSpinsY]*dot(self.spinArray[x][y][0],self.spinArray[x][(y+1)%self.nSpinsY][0]))
##                xDir = abs(self.couplingXArray[x][(x+1)%self.nSpinsX]*dot(self.spinArray[x][y][0],self.spinArray[(x+1)%self.nSpinsX][y][0]))
##                
##                if yDir > maxEnergy:        maxEnergy = yDir
##                if xDir > maxEnergy:        maxEnergy = xDir
##
##        for y in range(self.nSpinsY):
##            yDir = abs(self.couplingYArray[y][(y+1)%self.nSpinsY]*dot(self.spinArray[0][y][0],self.spinArray[(-1)%self.nSpinsX][y][0]))
##            if yDir > maxEnergy:            maxEnergy = yDir
##                                        
##        if maxEnergy != 0.0:
##            self.bondEnergyScale = .7/maxEnergy








  
##        commonAxis = vector(0.0,0.0,1.0)
##        
##        if self.nSpinsX > 1:    commonAxis = cross(self.torqueArray[0][0][0],self.torqueArray[2][0][0])       ## ??? only utilizes two spins ???
##        elif self.nSpinsY > 1:  commonAxis = cross(self.torqueArray[0][0][0],self.torqueArray[0][2][0])
##        else:                   commonAxis = self.spinArray[0][0][0]
##
##        if commonAxis[2] <= 0.0: commonAxis = -commonAxis
##        if commonAxis[2] == 0.0: commonAxis = (0.0,0.0,1.0)
##        
##        return norm(commonAxis)





##    def measurek(self):
##        commonAxis = self.getCommonAxis()
##
##        projectedUL = norm(self.spinArray[0][0][0] - dot(self.spinArray[0][0][0],commonAxis)*commonAxis)
##        projectedUR = norm(self.spinArray[self.nSpinsX-1][0][0] - dot(self.spinArray[self.nSpinsX-1][0][0],commonAxis)*commonAxis)
##        projectedBL = norm(self.spinArray[0][self.nSpinsY-1][0] - dot(self.spinArray[0][self.nSpinsY-1][0],commonAxis)*commonAxis)
##        
##        dotx = dot(projectedUL,((-1.0)**(self.nSpinsX-1))*projectedUR)
##        doty = dot(projectedUL,((1.0)**(self.nSpinsY-1))*projectedBL)
##       
##        if self.nSpinsX > 1:
##            if abs(dotx) < 1.0:     kx = arccos(dotx)
##            else:                   kx = pi
##        else:                       kx = 0.0
##
##        if self.nSpinsY > 1:
##            if abs(doty) < 1.0:     ky = arccos(doty)
##            else:                   ky = pi
##        else:                       ky = 0.0
##
##        return vector((kx%(2.0*pi)),(ky%(2.0*pi)),0.0)




##############################################################
##  TESTING CODE:                                           ##

##dt = .001
##
##
##Nx = 3
##Ny = 2
##uc = NumericUnitCell(Nx,Ny)
##
##Ja = -1.0
##Jbx = 1.8
##Jby = -1.0
##uc.setCouplings(Ja,Jbx,Jby)
##
##k = vector(1.0,.5,0.0)
##baseSigma = 0.001
##uc.setState(k,baseSigma,-1)


##
##print '\nspinArray:'
##print uc.getState()
##
##
##uc.getTorques()
##print '\nmeanFieldArray:'
##print uc.meanFieldArray
##print '\ntorqueArray:'
##print uc.torqueArray
##
##uc.timeEvolve(dt)
##print '\ntimeEvolved State:'
##print uc.getState()
##


##print '\n-----------------------------'
##print "Calculation Instance Started"
##print time.ctime()
##
##
##
##k = 0
##loops = 100000
##while k <= loops:
##    k+=1
##
##    uc.getTorques()
##    uc.timeEvolve(dt)
##
##
##print "\nCalculation Instance Ended For",loops,"Loops"
##print time.ctime()
##print '-----------------------------'
##
##print uc.getState()


#  NumericUnitCell:
##  63 seconds for 100,000 iterations with a 3 by 2 unit cell = 6 spins
##   6 seconds for 10,000 iterations with a 3 by 2 unit cell = 6 spins

##   4 seconds for 1,000 iterations with an 8 by 4 unit cell = 32 spins
##  33 seconds for 100 iterations with an 80 by 40 unit cell = 3,200 spins

## 301 seconds for 10 iterations with an 800 by 400 unit cell = 320,000 spins



#   newUnitCell:
##  43 seconds for 100,000 iterations with a 3 by 2 unit cell = 6 spins
##   4 seconds for 10,000 iterations with a 3 by 2 unit cell = 6 spins

##   2 seconds for 1,000 iterations with an 8 by 4 unit cell = 32 spins
##  18 seconds for 100 iterations with an 80 by 40 unit cell = 3,200 spins
## 343 seconds for 10 iterations with an 800 by 400 unit cell = 320,000 spins





## Notes:
## I would expect the new method (numeric matrices) will be faster any time we can actually utilize a matrix to do an operation.
## This makes sense and seems obvious, but since this is the difining quality, we must now ask what places we can use the matrix method.
## Matrix method works for:

## mean fields:  Since the coupling can be generated as a single matrix and does not need to be 'recreated' with each iteration.
## not Torques???:  This should be more straightforward than how it is currently implemented, where I iterate through the spin entries
## essentially a matrix by matrix cross product

